<?php
/**
 * Flea Site
 *
 * @copyright  Copyright (c) 2008 Movoin Studio (http://movoin.com)
 * @license    Apache License 2.0
 * @version    $Id: Guestbook.php 138 2009-05-25 06:42:38Z movoin $
 */

class Model_Guestbook
{

    var $tblComments;

    function Model_Guestbook()
    {
        $this->tblComments = & FLEA::getSingleton( 'Table_Comments' );
    }

    function saveMessage($colkey, $data)
    {
        $data['col_key'] = $colkey;
        if($this->tblComments->save($data))
            return '提交成功!';
        return '提交失败!';
    }

    function getMessage($comment_id)
    {
        return $this->tblComments->find($comment_id, null, 'comment_id,content,options,reply');
    }

    function replyMessage(&$data)
    {
        if($this->tblComments->updateField(array(array('comment_id', $data['comment_id'])), 'reply', $data['reply']))
            return '回复成功!';
        return '回复失败!';
    }
    
    function visibility($comment_id, $displayorder)
    {
        if($this->tblComments->updateField(array(array('comment_id', $comment_id)), 'displayorder', $displayorder))
            return '设置成功!';
        return '设置失败!';
    }

    function removeMessage($comment_id)
    {
        if($this->tblComments->removeByPkv((int)$comment_id))
            return '删除成功!';
        return '删除失败!';
    }

    /**
     * 返回表实例
     *
     */
    function &getTable()
    {
        return $this->tblComments;
    }
}
